import random
import time

from selenium.webdriver.common.by import By

from base import BaseAction


class DocGdPageHome(BaseAction):
    create_order_ele = By.XPATH, '//*[text()="新建订单"]'
    create_name_ele = By.XPATH, '//input[@placeholder="患者姓名"]'
    sex = random.choice(['男', '女'])
    create_sex_ele = By.XPATH, f'//span[text()="{sex} "]'
    create_year_ele2 = By.XPATH, '//*[@id="ZJaddWin"]//span[text()="2001"]'
    create_year_ele = By.XPATH, '//*[@data-tag="年"]//input'
    create_month_ele = By.XPATH, '//*[@data-tag="月"]//input'
    create_month_ele2 = By.XPATH, '//*[@id="ZJaddWin"]//span[text()="09"]'
    create_day_ele = By.XPATH, '//*[@data-tag="日"]//input'
    create_day_ele2 = By.XPATH, '//*[@id="date"]/div/p[6]/span[text()="06"]'
    next_ele = By.XPATH, '//span[text()="下一步"]'
    fac_ele = By.XPATH, '//input[@placeholder="请搜索并选择加工厂"]'
    quick_order_ele = By.XPATH, '//*[@id="ZJaddWin"]/div/div[3]/div[2]/div[2]/div[1]/div/div'
    requirement_notes_ele = By.XPATH, '//*[@id="ZJaddWin"]//textarea'  # 需求备注
    upload_upper_ele = By.XPATH, '//div[@class="upimgbg imgs1"]/following-sibling::div[1]/button[@class="yg-button default"]'
    upload_lower_ele = By.XPATH, '//div[@class="upimgbg imgs2"]/following-sibling::div[1]/button[@class="yg-button default"]'
    upload_success_ele = By.XPATH, '//*[text()="100%"]'
    recent_visit_ele = By.XPATH, '//span[text()="好友列表"]'
    submit_ele = By.XPATH, '//span[text()="提交"]'
    submit_success_ele = By.XPATH, '//*[text()="病例已提交"]'

    # 医生查看方案
    search1_js_ele = By.XPATH, '//*/form/div[2]/div/div/div'  # 点击筛选框
    search2_js_ele = By.XPATH, '//*[@class="yg-search-bar"]//div[2]//*[text()="方案待审核"]'  # 筛选病例
    search_js_button_ele = By.XPATH, '//*[text()="查询"]'  #
    see_ele = By.XPATH, '//*/tr[1]//i[2][text()="查看方案"]'  # 查看方案
    success_ele = By.XPATH, '//span[text()="0%"]'  # 判断进度条有没有到0
    view_scenarios_ele = By.XPATH, '//*[@id="playAraeFooter"]/button[3]'  # 播放方案按钮
    permission1_ele = By.XPATH, '//*[@id="app"]/div[2]/div/button[1]'  # 批准方案
    permission2_ele = By.XPATH, '//button[1]/span[text()="批准"]'  # 确认批准
    close_ele = By.XPATH, '//*[@id="app"]/div[4]/div[2]/div/span[7]/i'  # 关闭方案

    # 创建订单
    def get_create_order_ele(self):
        time.sleep(1)
        return self.get_element(self.create_order_ele)

    # 创建患者信息
    def get_create_name_ele(self):
        return self.get_element(self.create_name_ele)

    def get_create_sex_ele(self):
        return self.get_element(self.create_sex_ele)

    def get_create_year_ele(self):
        return self.get_element(self.create_year_ele)

    def get_create_month_ele(self):
        return self.get_element(self.create_month_ele)

    def get_create_day_ele(self):
        return self.get_element(self.create_day_ele)

    def get_create_year_ele2(self):
        return self.get_element(self.create_year_ele2)

    def get_create_month_ele2(self):
        return self.get_element(self.create_month_ele2)

    def get_create_day_ele2(self):
        return self.get_element(self.create_day_ele2)

    # 点击下一步
    def get_next_ele(self):
        return self.get_element(self.next_ele)

    def get_fac_ele(self):
        return self.get_element(self.fac_ele)

    def get_use_fac_ele(self, fac_name):
        use_fac_ele = By.XPATH, f'//*[@id="ZJaddWin"]//div[3]/div[2]/span[text()="{fac_name}"][1]'
        return self.get_element(use_fac_ele)

    def get_quick_order_ele(self):
        return self.get_element(self.quick_order_ele)

    def get_requirement_notes_ele(self):
        return self.get_element(self.requirement_notes_ele)

    def get_upload_upper_ele(self):
        return self.get_element(self.upload_upper_ele)

    def get_upload_lower_ele(self):
        return self.get_element(self.upload_lower_ele)

    def get_upload_success_ele(self):
        return self.get_element(self.upload_success_ele)

    def get_recent_visit_ele(self):
        return self.get_element(self.recent_visit_ele)

    def get_technician_ele(self, js_name):
        technician_ele = By.XPATH, f'//span[text()="{js_name}"]'
        return self.get_element(technician_ele)

    def get_submit_ele(self):
        return self.get_element(self.submit_ele)

    def get_submit_success_ele(self):
        return self.get_element(self.submit_success_ele)

    # 医生查看方案
    def get_search1_js_ele(self):
        return self.get_element(self.search1_js_ele)

    def get_search2_js_ele(self):
        return self.get_element(self.search2_js_ele)

    def get_search_js_button_ele(self):
        return self.get_element(self.search_js_button_ele)

    def get_see_ele(self):
        return self.get_element(self.see_ele)

    def get_view_scenarios_ele(self):
        return self.get_element(self.view_scenarios_ele)

    def get_permission1_ele(self):
        return self.get_element(self.permission1_ele)

    def get_permission2_ele(self):
        return self.get_element(self.permission2_ele)

    def get_close_ele(self):
        return self.get_element(self.close_ele)

    def get_success_ele(self):
        return self.get_element(self.success_ele)
